package com.stox.ui.swing.view;

import java.awt.BorderLayout;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.OrderComparator;

import com.stox.ui.swing.util.MessageSource;
import com.stox.ui.swing.widget.NavigatorTabbedPane;
import com.stox.ui.swing.widget.VTextIcon;
import com.stox.ui.swing.widget.wrapper.JTabbedPane;

@org.springframework.stereotype.Component
public class NavigatorView extends InternalFrameView implements InitializingBean {
	private static final long serialVersionUID = -2292138069258977312L;

	@Autowired
	private ApplicationContext applicationContext;
	
	@Autowired
	private NavigatorTabbedPane navigatorTabbedPane;

	public NavigatorView() {
		super(MessageSource.getMessage("Navigator"));
	}

	public void afterPropertiesSet() {
		navigatorTabbedPane.setTabPlacement(JTabbedPane.LEFT);

		List<NavigatorTab> tabs = new ArrayList<NavigatorTab>(applicationContext.getBeansOfType(NavigatorTab.class).values());
		OrderComparator.sort(tabs);
		for (NavigatorTab tab : tabs) {
			navigatorTabbedPane.addTab(null, new VTextIcon(navigatorTabbedPane, tab.getName(),
					VTextIcon.ROTATE_LEFT), (Component) tab);
		}

		navigatorTabbedPane.setSelectedComponent(applicationContext.getBean(ScripsPanel.class));
		getContentPane().add(navigatorTabbedPane, BorderLayout.CENTER);
	}

}
